import hilog from '@ohos.hilog';

const LOGGER_PREFIX: string = 'HraOta';

/**
 * 封装的日志工具类
 * 使用方法：
 * 例：Logger.debug(TAG, msg)，传入两个参数即可
 */
class Logger {
    //用于调试UI
    DEBUG_UI: boolean = false
    //日志开关
    DEBUG: boolean = true
    private domain: number;
    private prefix: string;
    private format: string = '%{public}s, %{public}s';

    constructor(prefix: string = '', domain: number = 0xFF00) {
        this.prefix = prefix;
        this.domain = domain;
    }

    debug(...args: string[]): void {
        if (!this.DEBUG) {
            return
        }
        hilog.debug(this.domain, this.prefix, this.format, args);
    }

    info(...args: string[]): void {
        if (!this.DEBUG) {
            return
        }
        hilog.info(this.domain, this.prefix, this.format, args);
    }

    warn(...args: string[]): void {
        if (!this.DEBUG) {
            return
        }
        hilog.warn(this.domain, this.prefix, this.format, args);
    }

    error(...args: string[]): void {
        hilog.error(this.domain, this.prefix, this.format, args);
    }
}

export default new Logger(LOGGER_PREFIX, 0xFF02);